const  timeutil= require('./timeutil');
const cloud = require('wx-server-sdk');

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
});
exports.main = async (event, context) => {
  // 获取基础信息
  const wxContext = cloud.getWXContext();
  let {OPENID}=cloud.getWXContext();
  const db=cloud.database();
  const _=db.command;
  const sid=event.sid;
  const time=timeutil.TimeCodeYmd();
  const timest=Date.now();
  var v= await 
  db.collection('all_team')
  .where({
    _openid:OPENID,
    'mySession_ids.session_id': sid,
  })
  .update({
    data:{
        'mySession_ids.$.leaveTime':time,
        'mySession_ids.$.leaveTimeST':timest,
    }
  })
  
  var t= await 
  db.collection('all_user')
  .where({
    _openid:OPENID,
    'mySession_ids.session_id': sid,
  })
  .update({
    data:{
        'mySession_ids.$.leaveTime':time,
        'mySession_ids.$.leaveTimeST':timest,
        'mySession_ids.$.unReadNum': parseInt(0) ,
    }
  })
  return v;
}